
package TransportesMarroquin;

import java.awt.Color;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;


public class CambioLlanta extends javax.swing.JFrame {

   Robot robot = null;
   boolean error =false;
   
    public CambioLlanta(int cod,String tipo,int codv,String pos) {
        initComponents();
        cold.setText(""+cod);
        ctip.setText(""+tipo);
        ccod.setText(""+codv);
        cpos.setText(""+pos);
        
        
        
        try{
         robot = new Robot();
      
      }
      catch(Exception e){System.out.println( e.toString() ); }
        robot.mouseMove(this.getSize().width/2,this.getSize().height/2);
        
    }

    private CambioLlanta() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

  
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lnum2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        ccod = new javax.swing.JTextField();
        ctip = new javax.swing.JTextField();
        cpos = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cold = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        cnew = new javax.swing.JTextField();
        ccam = new javax.swing.JButton();
        ccam1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                formMouseExited(evt);
            }
        });
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                formMouseMoved(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));
        jPanel1.setName("jPanel1"); // NOI18N

        lnum2.setFont(new java.awt.Font("Tahoma", 1, 18));
        lnum2.setForeground(new java.awt.Color(255, 255, 255));
        lnum2.setText("Cambió de Llanta");
        lnum2.setName("lnum2"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lnum2)
                .addContainerGap(257, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lnum2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel1.setText("Código Vehiculo");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("Tipo Vehiculo ");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText("Posicion Ocupada");
        jLabel3.setName("jLabel3"); // NOI18N

        ccod.setEnabled(false);
        ccod.setName("ccod"); // NOI18N

        ctip.setEnabled(false);
        ctip.setName("ctip"); // NOI18N

        cpos.setEnabled(false);
        cpos.setName("cpos"); // NOI18N

        jLabel4.setText("Codigo LLanta Vieja ");
        jLabel4.setName("jLabel4"); // NOI18N

        cold.setEnabled(false);
        cold.setName("cold"); // NOI18N

        jLabel5.setText("Codigo Llanta Nueva");
        jLabel5.setName("jLabel5"); // NOI18N

        cnew.setName("cnew"); // NOI18N
        cnew.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cnewKeyTyped(evt);
            }
        });

        ccam.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/aceptar.png"))); // NOI18N
        ccam.setText("Cambiar ");
        ccam.setName("ccam"); // NOI18N
        ccam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ccamActionPerformed(evt);
            }
        });

        ccam1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        ccam1.setText("Cancelar");
        ccam1.setName("ccam1"); // NOI18N
        ccam1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ccam1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(ctip, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
                        .addComponent(cpos, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(cold, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                            .addComponent(jLabel5)
                            .addGap(10, 10, 10)
                            .addComponent(cnew, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(ccod, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(176, Short.MAX_VALUE)
                .addComponent(ccam)
                .addGap(18, 18, 18)
                .addComponent(ccam1)
                .addGap(38, 38, 38))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(ccod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(ctip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cpos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(cnew, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ccam)
                    .addComponent(ccam1))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ccamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ccamActionPerformed
       error=false;
        try{
                Error va = new Error();
                va.instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values('" + cnew.getText()+ "','"+ctip.getText()+"','"+ccod.getText()+"','"+cpos.getText()+"')");
                va.conexion.close();
                va.instruccion.close();
                
            }catch (Exception e ){
                error=true;
                cnew.setText(""+"Error");
                cnew.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Instrucción incompleta, al parecer''"+cnew.getText() +"'' ya existente");
            }
        
        if(error==false){
              Error.Mysql("UPDATE llanta SET cementerio = 'si' where idnumeconomico = "+cold.getText());
           
            // reconfiguro todo 
               Llantas.consulta = "SELECT * FROM llanta WHERE cementerio like 'no'";
                      try{

                Llantas.tableModel = new ResultSetTableModel( Llantas.consulta );
                }
                catch ( Exception e) {
                 JOptionPane.showMessageDialog( null,
                 e );}
                      Llantas.resultTable.setModel(Llantas.tableModel);
                       dispose();
        }
}//GEN-LAST:event_ccamActionPerformed

    private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
                 
               int ancho = this.getX()+this.getSize().width;
               int largo = this.getY()+this.getSize().height;
               
      
      
      if(evt.getX()>=465||evt.getY()>=250||evt.getX()<=10||evt.getY()<=30)
      {
         
         robot.mouseMove(ancho/2, largo/2);
            
      }
   
     
    }//GEN-LAST:event_formMouseMoved

    private void formMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseExited
     
    }//GEN-LAST:event_formMouseExited

    private void ccam1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ccam1ActionPerformed
      dispose();
    }//GEN-LAST:event_ccam1ActionPerformed

    private void cnewKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cnewKeyTyped
        char c = evt.getKeyChar();
        if (!(Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))
        {
            getToolkit().beep();
            evt.consume();
        }

    }//GEN-LAST:event_cnewKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CambioLlanta().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ccam;
    private javax.swing.JButton ccam1;
    public static javax.swing.JTextField ccod;
    public static javax.swing.JTextField cnew;
    public static javax.swing.JTextField cold;
    public static javax.swing.JTextField cpos;
    public static javax.swing.JTextField ctip;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lnum2;
    // End of variables declaration//GEN-END:variables
}
